package com.zjitc.service.Impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zjitc.dao.UserDao;
import com.zjitc.domain.ResultPage;
import com.zjitc.domain.User;
import com.zjitc.service.UserService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UserDao,User> implements UserService {
    @Autowired
    private UserDao userDao;
    @Override
    public ResultPage<User> findPage(int currentPage, int pageSize, User user) {
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(Strings.isNotEmpty(user.getUsername()), User::getUsername,
                user.getUsername());
        wrapper.like(Strings.isNotEmpty(user.getGender()), User::getGender,
                user.getGender());
        wrapper.like(Strings.isNotEmpty(user.getEmail()), User::getEmail,
                user.getEmail());
        IPage<User> page = new Page<>(currentPage, pageSize);
        userDao.selectPage(page, wrapper);
        return new ResultPage<User>(page.getTotal(), page.getRecords());
    }




}
